const { t } = useI18n() // 国际化
export const accountRule = (_rule, value, callback) => {
  const reg = /^[a-zA-Z0-9_\-\@\.]{3,16}$/
  if (!value) {
    callback(new Error(t('sign.fields.account.rules', 'empty')))
  } else if (!reg.test(value)) {
    callback(new Error(t('sign.fields.account.rules', 'error')))
  } else {
    callback()
  }
}

export const emailRule = (_rule, value, callback) => {
  const reg = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/
  if (!value) {
    callback(new Error(t('sign.fields.email.rules', 'empty')))
  } else if (!reg.test(value)) {
    callback(new Error(t('sign.fields.email.rules', 'error')))
  } else {
    callback()
  }
}

export const phoneRule = (_rule, value, callback) => {
  const reg = /^1((34[0-8])|(8\d{2})|(([35][0-35-9]|4[579]|66|7[35678]|9[1389])\d{1}))\d{7}$/
  if (!value) {
    callback(new Error(t('sign.fields.phone.rules', 'empty')))
  } else if (!reg.test(value)) {
    callback(new Error(t('sign.fields.phone.rules', 'error')))
  } else {
    callback()
  }
}

// 必填项
export const required = {
  required: true,
  message: t('common', 'required')
}
